<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    :close-on-click-modal="false"
    width="400px"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="购买数量" prop="num">
        <el-input-number v-model="form.num" :min="1" :max="10000" style="width: 150px;"></el-input-number>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" :disabled="listLoading" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>

import { doUpdateOrderDetail } from '@/api/order'

export default {
  name: 'EditDetailsNum',
  data() {
    return {
      form: {
        id: '',
        orderId:'',
        num: null,
      },
      row:null,
      order:null,
      rules: {
        num: [
          { required: true, trigger: 'blur', message: '请输入购买数量' },
        ]
      },
      title: '',
      minDate:'',
      listLoading:false,
      dialogFormVisible: false,
    }
  },
  created() {},
  methods: {
    showEdit(row) {
      this.title = '修改购买数量'
      this.row = row
      this.form.id = row.id
      this.form.orderId = row.orderId
      this.form.num = row.num
      this.dialogFormVisible = true
    },
    close() {
      this.dialogFormVisible = false
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          let msg = ''
          msg = '购买数量修改成功'
          this.listLoading = true
          await doUpdateOrderDetail(this.form)
          this.$baseMessage(msg, 'success')
          //this.row.orderDetailEntities  = []
          this.$emit('fetch-data',this.form.orderId)
          //回更订单详细数据
          this.listLoading = false
          this.close()
        } else {
          return false
        }
      })
    },
  },
}
</script>
